local zhiheng = fk.CreateSkill {
  name = "lingling__zhiheng",
}

Fk:loadTranslationTable{
  ["lingling__zhiheng"] = "制衡",
  [":lingling__zhiheng"] = "每回合限两次，当你获得牌后，你可以弃置两张颜色不同的牌，然后摸三张牌。",

  ["#lingling__zhiheng-invoke"] = "制衡：你可以弃置两张颜色不同的牌，摸三张牌",
}

zhiheng:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(zhiheng.name) and #player:getCardIds("he") > 1 and
      player:usedSkillTimes(zhiheng.name, Player.HistoryTurn) < 2 then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askToUseActiveSkill(player, {
      skill_name = "lingling__zhiheng_active",
      prompt = "#lingling__zhiheng-invoke",
      cancelable = true,
    })
    if success and dat then
      event:setCostData(self, {cards = dat.cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, zhiheng.name, player, player)
    if not player.dead then
      player:drawCards(3, zhiheng.name)
    end
  end,
})

return zhiheng
